<?php
include_once 'prepend.inc.php';

$cndASIN = QQ::AndCondition(QQ::Equal(QQN::Myassets()->Asin, $_ITEM->ASIN), QQ::Equal(QQN::Myassets()->Owner,$_SESSION['User']));
$cndTitle = QQ::AndCondition(QQ::Equal(QQN::Myassets()->Title, $_ITEM->ASIN), QQ::Equal(QQN::Myassets()->Owner,$_SESSION['User']));
$cntASIN = Myassets::QueryCount($cndASIN);
$cntTitle = Myassets::QueryCount($cndTitle);
if($cntASIN <> 0 || $cntTitle <> 0 )
{
	$owned = true;
}
else
{
	$owned = false;
}

?>
<table>
	<tr>
		<td><?php
		try
		{
			if(isset($_ITEM->MediumImage->Url)){$img = $_ITEM->MediumImage->Url;}else{$img = '../assets/images/48x48/help.png';}
		}
		catch (Exception $e)
		{
			$img = '../../assets/images/48x48/help.png';
		}
		?> <img src='<?php _p($img);?>' width=108px height=160px></img></td>
		<td>
		<div><a href=<?php _p($_ITEM->DetailPageURL); ?>><?php isset($_ITEM->Title)?_p($_ITEM->Title):_p('');?></a>
		</div>
		<?php if($_ITEM->ProductGroup == "Book") { //Book template begins here ?>
		<div>ASIN: <?php isset($_ITEM->ASIN)?_p($_ITEM->ASIN):_p('');?></div>
		<div><?php 
		$strAuthor = '';
		if(isset($_ITEM->Author))
		{
			if(is_array($_ITEM->Author))
			{
				foreach($_ITEM->Author as $val)
				{
					$strAuthor  =  $strAuthor . ',' . $val ;
				}
			}
			else
			{
				$strAuthor = $_ITEM->Author;
			}

			_p($strAuthor);
		}
		?></div>
		<div><?php isset($_ITEM->Binding)?_p($_ITEM->Binding):_p('');?></div>
		<div><?php $intPages = 0;isset($_ITEM->NumberOfPages)?$intPages = $_ITEM->NumberOfPages: $intPages = 0; _p($intPages);?>
		Pages</div>
		<div>Published By: <?php $strPublisher ='';isset($_ITEM->Publisher)?$strPublisher = $_ITEM->Publisher :$strPublisher = 'Unavailable'; _p($strPublisher);?>
		</div>

		<?php
		//Movies template begins here
		}
		elseif($_ITEM->ProductGroup == "DVD")
		{ ?>
		<div>ASIN: <?php isset($_ITEM->ASIN)?_p($_ITEM->ASIN):_p('');?></div>
		<div>Cast: <?php $strActor = '';if(isset($_ITEM->Actor)){if(is_array($_ITEM->Actor)){foreach($_ITEM->Actor as $val){$strActor  =  $strActor . ',' . $val ;}}else{$strActor = $_ITEM->Actor;} _p($strActor);}?></div>
		<div>Director: <?php $strDirector = '';if(isset($_ITEM->Director)){if(is_array($_ITEM->Director)){foreach($_ITEM->Director as $val){$strDirector  =  $strDirector . ',' . $val ;}}else{$strDirector = $_ITEM->Director;} _p($strDirector);}?>
		</div>
		<div>Movie Time: <?php $intRunningTime = 0;if(isset($_ITEM->RunningTime)){$intRunningTime = $_ITEM->RunningTime; _p($_ITEM->RunningTime);} else{_p('Unavailable');}?>
		minutes</div>
		<?php }
		elseif($_ITEM->ProductGroup == "Music")
		{?>
		<div>ASIN: <?php isset($_ITEM->ASIN)?_p($_ITEM->ASIN):_p('');?></div>
		<div>Artist: <?php $strArtist = '';if(isset($_ITEM->Artist)){if(is_array($_ITEM->Artist)){foreach($_ITEM->Artist as $val){$strArtist  =  $strArtist . ',' . $val ;}}else{$strArtist = $_ITEM->Artist;}}?></div>
		<div>Label: <?php isset($_ITEM->Label)?_p($_ITEM->Label):_p('');?></div>
		<div>Number of Discs: <?php $strNumberOfDiscs = 0;if(isset($_ITEM->NumberOfDiscs)){$strNumberOfDiscs =$_ITEM->NumberOfDiscs; _p($_ITEM->NumberOfDiscs);}else{_p('');}?>
		</div>

		<?php
		$strLightId = 'light'.$_ITEM->ASIN;
		$strFadeId = 'fade'.$_ITEM->ASIN;
		?>
		<div><a href="javascript:void(0)"
			onclick="document.getElementById('<?php _p($strLightId); ?>').style.display='block';document.getElementById('<?php _p($strFadeId); ?>').style.display='block'">Tracks</a>
		<div id="<?php _p($strLightId); ?>" class="white_content"><a
			href="javascript:void(0)"
			onclick="document.getElementById('<?php _p($strLightId); ?>').style.display='none';document.getElementById('<?php _p($strFadeId); ?>').style.display='none'">Close</a>
		<br />
		<br />
		<?php
		if(isset($_ITEM->Tracks))
		foreach($_ITEM->Tracks as $val)
		{
			echo('<b>' . $val . '</b>' . '<br>');
		}
		?></div>
		<div id="<?php _p($strFadeId); ?>" class="black_overlay"></div>

		</div>
		<?php }
		$item_pass = '';
		$item_pass  = $_ITEM->ASIN
		. '~' . $_ITEM->Title
		. '~' . $_ITEM->ProductGroup
		. '~' . $img
		. '~' . $_ITEM->DetailPageURL;

		switch($_ITEM->ProductGroup)
		{
			case 'Book':
				$strISBN = isset($_ITEM->ISBN)?$_ITEM->ISBN:'';
				$calPublicationDate = isset($_ITEM->PublicationDate)?$_ITEM->PublicationDate:0000-00-00;
				$tempstr =  $strAuthor. '~' . $_ITEM->Binding . '~'. $intPages . '~' . $strPublisher . '~' . $calPublicationDate . '~' . $strISBN;
				$item_pass = $item_pass . '~' . $tempstr;
				break;
			case 'DVD':
				$tempstr =  $strActor. '~' . $strDirector . '~'. $intRunningTime;
				$item_pass = $item_pass . '~' . $tempstr;
				break;
			case 'Music':
				$tempstr =  $strArtist. '~' . $_ITEM->Label . '~'. $strNumberOfDiscs ;
				$item_pass = $item_pass . '~' . $tempstr;
				break;
		}

		if($owned == true)
		{
			$imgAddLink = new QImageButton($this->dtrAmazon);
			$imgAddLink->ImageUrl = '../assets/images/48x48/heart.png';
			$imgAddLink->ToolTip = 'You Own this';
		}
		else
		{
			$imgAddLink = new QImageButton($this->dtrAmazon);
			$imgAddLink->ImageUrl = '../assets/images/48x48/add.png';
			$imgAddLink->AddAction(new QClickEvent(),new QServerAction('AddClicked'));
			$imgAddLink->ToolTip = 'Add to collection';
			$imgAddLink->ActionParameter  = $item_pass;
		}

		$imgAddLink->Render();
		?></td>
	</tr>

</table>
